function throttle(fn, interval, { leading, trailing,resultCallback } = { leading: true, trailing: false }) {
  let lastTime = 0
  let timer = null
  function _throttle(...args) {

    let startTime = new Date().getTime()
    if (!lastTime && !leading) lastTime = startTime;
    let remainTime = interval - (startTime - lastTime)

    if (remainTime <= 0) {
      if(timer) {
        clearTimeout(timer)
        timer = null
      }
      let result = fn.apply(this, ...args)
      if(result) resultCallback(result) 
      lastTime = startTime
      result
    }

    if(trailing && !timer) {
      timer = setTimeout(() => {
        timer = null
        // 第一次不要执行, 0  不然就 有值就可以了
        lastTime = !leading ? 0 : new Date().getTime()
        let result = fn.apply(this, ...args)
        if(result) resultCallback(result) 
      }, remainTime)
    }
  }

  _throttle.cancel = function () {
    timer ? clearTimeout(timer) : null;
    lastTime = 0;
    timer = null;
  }

  return _throttle
}